package com.chen.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CorsMvcConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry r) {
        r.addMapping("/**")
         .allowedOrigins("http://localhost:5173")
         .allowedMethods("GET","POST","PUT","DELETE","OPTIONS")
         .allowedHeaders("*")
         .allowCredentials(true)
                .exposedHeaders("Authorization")//暴露它，否则浏览器拿不到：
                // 和 Access-Control-Expose-Headers: Authorization 是同一个目的

         .maxAge(3600);

    }
}